package net.zdreamer.geracomium.ui.home;

import com.example.geracomium.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import net.zdreamer.geracomium.adapter.CommentListAdapter;
import net.zdreamer.geracomium.entity.CommentInfos;
import net.zdreamer.geracomium.ui.BaseActivity;
import net.zdreamer.geracomium.ui.more.PersonalCenterActivity;

public class CommentActivity extends BaseActivity implements OnClickListener{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	private PullToRefreshListView pullToRefreshListView;
	private CommentListAdapter mAdapter;
	private ImageView back, share;

	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.activity_comment;
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		((TextView)findViewById(R.id.title_content)).setText("评论");

	}

	@Override
	protected void initViews() {
		// TODO Auto-generated method stub
		pullToRefreshListView = (PullToRefreshListView) findViewById(R.id.listview_nurse);
		pullToRefreshListView.setMode(Mode.BOTH);
		CommentInfos nurse = new CommentInfos();
		mAdapter = new CommentListAdapter(this, nurse.nurseReviewInfos,
				R.layout.comment_list_item);
		pullToRefreshListView.setAdapter(mAdapter);
		pullToRefreshListView.setOnRefreshListener(orl);
	}

	@Override
	protected void initListener() {
		// TODO Auto-generated method stub

	}

	private OnRefreshListener<ListView> orl = new OnRefreshListener<ListView>() {

		@Override
		public void onRefresh(PullToRefreshBase<ListView> refreshView) {
			String label = DateUtils.formatDateTime(getApplicationContext(),
					System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME
							| DateUtils.FORMAT_SHOW_DATE
							| DateUtils.FORMAT_ABBREV_ALL);

			refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(
					"上次刷新：" + label);

			Thread a = new Thread(new Runnable() {
				@Override
				public void run() {
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					Message message = new Message();
					message.what = 0;
					h.sendMessage(message);
				}
			});
			a.start();
		}
	};
	Handler h = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			if (msg.what == 0) {
				CommentInfos nurse = new CommentInfos();
				mAdapter = new CommentListAdapter(CommentActivity.this,
						nurse.nurseReviewInfos, R.layout.comment_list_item);
				pullToRefreshListView.setAdapter(mAdapter);
				pullToRefreshListView.onRefreshComplete();
			}
		}

	};

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			Intent intent = new Intent(this,
					PersonalCenterActivity.class);
			startActivity(intent);
			this.finish();

			break;
		default:
			break;
		}
	}

}
